package com.cby.android.sample.adapter

import android.content.Context
import android.widget.ImageView
import cn.bingoogolapple.bgabanner.BGABanner
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.cby.android.sample.R
import com.cby.android.sample.bean.wan.WanBannerBean

class BannerAdapter(private val context: Context) : BGABanner.Adapter<ImageView, WanBannerBean> {
    override fun fillBannerItem(
        banner: BGABanner?,
        itemView: ImageView?,
        model: WanBannerBean?,
        position: Int
    ) {
        val options = RequestOptions().apply {
            fitCenter()
            placeholder(R.drawable.loading_bixue)
            error(R.drawable.loading_bixue)
            diskCacheStrategy(DiskCacheStrategy.ALL)
        }
        if (itemView != null) {
            Glide.with(context.applicationContext).load(model?.imagePath).apply(options).into(itemView)
        }
    }
}